package com.pisolution.scheduler.datasource.command;

import com.pisolution.scheduler.datasource.instance.FailureStrategy;
import com.pisolution.scheduler.datasource.instance.Priority;
import com.pisolution.scheduler.datasource.instance.WarningType;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.util.Date;

/**
 * 系统控制指令数据实体.
 *
 * @author sora
 * @version 0.1.0
 */
@TableName(value = "command")
public class Command {
    // -------------------------------------------------------------------------------------------------
    //  数据单元 (基础信息)
    // -------------------------------------------------------------------------------------------------

    /** 指令标识. */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /** 指令类型. */
    @TableField(value = "type")
    private CommandType type;

    /** 指令参数. */
    @TableField(value = "params")
    private String params;

    /** 处理时间. */
    @TableField(value = "start_time")
    private Date startTime;

    /** 更新时间. */
    @TableField(value = "update_time")
    private Date updateTime;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (关联信息)
    // -------------------------------------------------------------------------------------------------

    /** 工作流标识. */
    @TableField(value = "workflow_id")
    private int workflowId;

    /** 工作流实例优先级. */
    @TableField(value = "priority")
    private Priority priority;

    /** 运行工作流实例的工作节点分组. */
    @TableField(value = "worker_group")
    private String workerGroup;

    /** 工作流实例运行失败时的策略. */
    @TableField(value = "strategy")
    private FailureStrategy strategy;

    /** 工作流实例运行期告警类型. */
    @TableField(value = "warning_type")
    private WarningType warningType;

    /** 工作流实例告警组标识. */
    @TableField(value = "warning_group_id")
    private Integer warningGroupId;

    /** 工作流实例调度时间. */
    @TableField(value = "schedule_time")
    private Date scheduleTime;

    // -------------------------------------------------------------------------------------------------
    //  初始化
    // -------------------------------------------------------------------------------------------------

    /**
     * 初始化控制指令.
     */
    public Command() {
        this.updateTime = new Date();
        this.strategy = FailureStrategy.CONTINUE;
        this.startTime = new Date();
    }

    /**
     * 初始化控制指令.
     *
     * @param type 指令类型.
     * @param params 指令参数.
     * @param workflowId 工作流标识.
     * @param priority 工作流实例优先级.
     * @param workerGroup 运行工作流实例的工作节点分组.
     * @param strategy 工作流实例运行失败时的策略.
     * @param warningType 工作流实例运行期告警类型.
     * @param warningGroupId 工作流实例告警组标识.
     * @param scheduleTime 工作流实例调度时间.
     */
    public Command(
        final CommandType type,
        final String params,
        final int workflowId,
        final Priority priority,
        final String workerGroup,
        final FailureStrategy strategy,
        final WarningType warningType,
        final Integer warningGroupId,
        final Date scheduleTime
    ) {
        this.type = type;
        this.params = params;
        this.workflowId = workflowId;
        this.priority = priority;
        this.workerGroup = workerGroup;
        this.strategy = strategy;
        this.warningType = warningType;
        this.warningGroupId = warningGroupId;
        this.scheduleTime = scheduleTime;

        this.startTime = new Date();
        this.updateTime = new Date();
    }

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public CommandType getType() {
        return this.type;
    }

    public void setType(CommandType type) {
        this.type = type;
    }

    public String getParams() {
        return this.params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    public Date getStartTime() {
        return this.startTime;
    }

    public Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public int getWorkflowId() {
        return this.workflowId;
    }

    public void setWorkflowId(int workflowId) {
        this.workflowId = workflowId;
    }

    public Priority getPriority() {
        return this.priority;
    }

    public void setPriority(Priority priority) {
        this.priority = priority;
    }

    public String getWorkerGroup() {
        return this.workerGroup;
    }

    public FailureStrategy getStrategy() {
        return this.strategy;
    }

    public WarningType getWarningType() {
        return this.warningType;
    }

    public Integer getWarningGroupId() {
        return this.warningGroupId;
    }

    public Date getScheduleTime() {
        return this.scheduleTime;
    }
}
